﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<Committee>

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "คณะกรรมการ";
    ViewBag.Descr = "ข้อมูล" + ViewBag.Title + " ที่ร้องขอ";
    int committeeGroupId = ViewBag.committeeGroupId;
}

@using (Html.BeginForm("DeleteAll", "Committee", FormMethod.Post, new { id = "form" }))
{
     @Html.AntiForgeryToken()

    <div class="row-fluid">
        @if(ViewBag.EmptyLayout!=true)
        {
            <div class="block-button-menu-above row-fluid">
                 
                    @Html.ActionLink("เพิ่ม", "Create", new {committeeGroupId = committeeGroupId}
                                     , new {@class = "btn btn-small btn-success button-standard-width", role = "button"})
                    @Html.ButtonDeleteAll()
                    @Html.ActionLink("  รายงานคำสั่งแต่งตั้งคณะกรรมการ", "Report", new {committeeGroupId = committeeGroupId}
                                     , new {@class = "btn button-standard-width btn-small btn-blue icon-file bigger-120", role = "button"})
                
                
            </div>
        }

       <div class="alert-error">@Html.ValidationSummary()</div>
        @* Header Table *@
            <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
                    @ViewBag.Title 
                    <span style="color:rgb(48, 126, 203)">กลุ่มข้อมูลไอดี: @ViewBag.committeeGroupId</span>
                </div>
				    @Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
                        <label>
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>  
                    <th>
                        @Html.DisplayNameFor(model => model.ComFunctionId)                            
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Code)        
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.ComPositionId)     
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.EmpName)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.EmpPositionName) 
                    </th>
                    <th class="center" style="width:80px;">
                        &nbsp;
                    </th>
                </tr>
            </thead>
            <tbody>
                @{
                    var data = Model ?? new List<Committee>();
                    // oRDER BY ชุดที่ -> หน้าที่ของกรรมการ -> ตำแหน่งของกรรมการ
                    var resorted = data.OrderBy(o =>o.Code).ThenBy(p=>p.ComFunctionId).ThenBy(q=>q.ComPositionId).ToList();
                }

                @foreach (var m in resorted)
                {
                    <tr>
                        <td class="center">
                            <!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.CommitteeId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>
                        <td>
                            @if(ViewBag.EmptyLayout != true)
                            {
                                @Html.ActionLink(m.CommitteeFunction.LookUpName, "Details", new {Id = m.CommitteeId})
                            } else
                            {
                                @Html.DisplayFor(model => m.CommitteeFunction.LookUpName)
                            }
                        </td>
                        <td>
                            @if (ViewBag.EmptyLayout != true)
                            {
                                @Html.ActionLink(m.Code, "Details", new { Id = m.CommitteeId })
                            }
                            else
                            {
                                @Html.DisplayFor(model => m.Code)
                            }
                        </td>
                        <td>
                            @if (ViewBag.EmptyLayout != true)
                            {
                                @Html.ActionLink(m.CommitteePosition.LookUpName, "Details", new { Id = m.CommitteeId })
                            }
                            else
                            {
                                @Html.DisplayFor(model => m.CommitteePosition.LookUpName)
                            }
                        </td>
                        <td>
                            @if (ViewBag.EmptyLayout != true)
                            {
                                @Html.ActionLink(m.EmpName, "Details", new { Id = m.CommitteeId })
                            }
                            else
                            {
                                @m.EmpName
                            }
                        </td>
                        <td>
                            @Html.DisplayFor(model => m.EmpPositionName) 
                        </td>
                        <td class="td-actions">
                            @if (ViewBag.EmptyLayout != true)
                            {
                                @Html.Partial("_ButtonMenuEachRow", new KPIS.GERP.Models.ViewModel.ExportGrid
                                    {
                                        Id = m.CommitteeId,
                                        DetailsUrl = Url.Action("Details") + "/" + m.CommitteeId + "?CommitteeGroupId=" + m.CommitteeGroupId,
                                        EditUrl = Url.Action("Edit") + "/" + m.CommitteeId+ "?CommitteeGroupId=" + m.CommitteeGroupId,
                                        DeleteUrl = Url.Action("Delete") + "/" + m.CommitteeId+ "?CommitteeGroupId=" + m.CommitteeGroupId
                                    })
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}



@section scripts {
    
	<script type="text/javascript">
		$(function () {
		    var oTable1 = $('#table').dataTable({
		        "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    null,
                    null,
                    null,
                    { "bSortable": false }
		        ]
		    });

		    $('table th input:checkbox').on('click', function () {
		        var that = this;
		        $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
		    });

		    $('[data-rel=tooltip]').tooltip();

		    $("#form").submit(function () {
		        var currentForm = this;
		        bootbox.confirm(function (result) {
		            var _result = result;
		            if (result) {
		                $.ajax({
		                    url: '@(Url.Action("DeleteAll", "Committee"))',
		                    type: "post",
		                    dataType: "json",
		                    data: $(currentForm).serialize(),
		                    success: function (result) {
		                        if (result.success) {
		                            location.reload();
		                        } else {
		                        }
		                    }
		                });
		            }
		        })
		        return false;

		    });

		})

	</script>

}
